﻿// $Id: ShowErrorList.cs 67 2008-05-07 21:07:39Z nvivo $

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DBLGen.GUI.Forms
{
    public partial class ShowErrorList : Form
    {
        private ErrorMessage[] _messages;

        public ShowErrorList(ErrorMessage[] messages)
        {
            if (messages == null)
                throw new ArgumentNullException("messages");

            _messages = messages;

            InitializeComponent();
        }

        private void ErrorListException_Load(object sender, EventArgs e)
        {
            gvErrors.AutoGenerateColumns = false;
            gvErrors.DataSource = new BindingSource(_messages, null);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void gvErrors_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            for (int i = 0; i < gvErrors.Rows.Count; i++)
            {
                ErrorMessageSeverity severity = (ErrorMessageSeverity) gvErrors["SeverityColumn", i].Value;
                DataGridViewCell cell = gvErrors["IconColumn", i];

                switch (severity)
                {
                    case ErrorMessageSeverity.Error:
                        cell.Value = Icons.exclamation;
                        break;
                    case ErrorMessageSeverity.Warning:
                        cell.Value = Icons.error;
                        break;
                }
            }
        }

        private void gvErrors_SelectionChanged(object sender, EventArgs e)
        {
            gvErrors.ClearSelection();
        }
    }
}
